package org.qloudgen.borg.pages.compnent;

import java.io.Serializable;

import org.apache.wicket.validation.IErrorMessageSource;
import org.apache.wicket.validation.IValidatable;
import org.apache.wicket.validation.IValidationError;
import org.apache.wicket.validation.IValidator;

public class ParamDigitValidator implements IValidator<String> {

	private static final long serialVersionUID = 1L;
	
	@Override
	public void validate(IValidatable<String> validatable) {
		
		boolean flag = true; 
		
		String value = validatable.getValue().toString();
System.out.println(value);		
		try {
			Float.valueOf(value) ;
			flag = false;
System.out.println("digit ok");
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		if (flag) {
			
			IValidationError error = new IValidationError(){

				private static final long serialVersionUID = 1L;

				@Override
				public Serializable getErrorMessage(
						IErrorMessageSource messageSource) {
System.out.println("digit error");
					return "请输入数字";
				}
				
			};
			
			validatable.error(error);
		}
	}

}
